﻿using AutoMapper;
using Hotel.Common;
using Hotel.Domain;
using Hotel.IServices;
using Hotel.IServices.RequestDTO;
using Hotel.IServices.ResponseDTO;
using Hotel.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RBACController : ControllerBase
    {
        private readonly IRBACServices rbacServices;
        private readonly ILogger<RBACServices> logger;

        public RBACController(IRBACServices rbacServices, ILogger<RBACServices> logger)
        {
            this.rbacServices = rbacServices;
            this.logger = logger;
        }




        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost("RegisterAsync")]
        public async Task<ApiResult<bool>> RegisterAsync(RegisterAsyncReqDto dto)
        {
            try
            {
                return await rbacServices.RegisterAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取角色下拉框
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet("ShowRoleAsync")]
        public async Task<ApiResult<List<ShowRoleAsyncReqDto>>> ShowRoleAsync()
        {
            try
            {
                return  await rbacServices.ShowRoleAsync();
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 显示用户列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet("ShowUserAsync")]
        public async Task<ApiResult<PagingResult<IList<ShowUserAsyncReqDto>>>> ShowUserAsync([FromQuery]UserAsyncPageReqDto dto)
        {
            try
            {
                return await rbacServices.ShowUserAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 用户查询
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        /// 
        [HttpGet("GetUserInfoAsync")]
        public async Task<ApiResult<GetUserInfoAsyncReqDto>> GetUserInfoAsync(int userid)
        {
            try
            {
                return await rbacServices.GetUserInfoAsync(userid);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 用户修改,用户角色修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPut("UpDateUserInfoRegisterAsync")]
        public async Task<ApiResult<bool>> UpDateUserInfoRegisterAsync(UpDateUserInfoRegisterAsyncReqDto dto)
        {
            try
            {
                return await rbacServices.UpDateUserInfoRegisterAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 添加角色权限
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost("AddRoleAsync")]
        public async Task<ApiResult> AddRoleAsync(AddRoleAsyncReqDto dto)
        {
            try
            {
                return await rbacServices.AddRoleAsync(dto);
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 获取权限列表个数
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet("GetPermissionListAsync")]
        public async Task<ApiResult<List<TreeReqDto>>> GetPermissionListAsync()
        {
            try
            {
                return await rbacServices.GetPermissionListAsync();
            }
            catch (Exception)
            {

                throw;
            }
        }




        /// <summary>
        /// 获取权限树状图
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        [HttpGet("GetPermissionTreeAsync")]
        public async Task<ApiResult<List<GetMenuListYserIdAsyncReqDto>>> GetMenuListYserIdAsync(int userid)
        {
            try
            {
                return await rbacServices.GetMenuListYserIdAsync(userid);


            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
